import {AxiosPromise} from "axios";
import {Result, TableDataInfo} from "@/model";
import {MsgLastVO, MsgQuery} from "@/api/msg/types";
import request from "@/utils/request";

/**
 * 获取好友之间的最后一条聊天记录
 * @returns 聊天记录
 */
export function getLastMsg(roomId: string): AxiosPromise<Result<MsgLastVO[]>> {
    return request({
        url: `/msg/getLastMsg/${roomId}`,
        method: "get",
    });
}

/**
 * 获取最近的聊天记录
 * @param params 房间号和分页参数
 * @returns 聊天记录
 */
export function getRecentMsg(params: MsgQuery): AxiosPromise<TableDataInfo> {
    return request({
        url: `/msg/listRecent`,
        method: "get",
        params,
    });
}

/**
 * 查询用户历史聊天记录
 * @returns 聊天记录
 */
export function getHistoryMsg(params: MsgQuery): AxiosPromise<TableDataInfo> {
    return request({
        url: `/msg/listHistory`,
        method: "get",
        params,
    });
}

/**
 * 标记消息已读
 */
export function readMsg(roomId: string): AxiosPromise<Result<null>> {
    return request({
        url: `/msg/readMsg/${roomId}`,
        method: "get",
    });
}